package com.ztk.jdk.jdk8.lambad;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Lambda01 {

    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("小五", 18));
        list.add(new Person("小四", 19));
        list.add(new Person("小三", 17));
        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person p1, Person p2) {
                return p1.getAge() - p2.getAge();
            }
        });

        list.forEach( p -> System.out.println(p));
        list.forEach(System.out::println);

        Collections.sort(list, (p1, p2) -> Integer.compare(p1.getAge(), p2.getAge()));

        Collections.sort(list, Comparator.comparingInt(Person::getAge));
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class Person {
    private String name;
    private int age;
}